//
// Created by HP on 2024/4/27.
//

#include "aurora_img.h"


Aurora_Img::Aurora_Img(LCD_Driver *lcd,Aurora_Font *font){
    _lcd = lcd;
    _font = font;
    curr_img_index = 0;
}


void Aurora_Img::show_next_img(){
    curr_img_index = ( curr_img_index == (IMG_INDEX_MAX-1)) ? curr_img_index : ( curr_img_index +1);

    uint16_t j;
    uint8_t *color = (uint8_t *)malloc(sizeof (uint8_t)*320*164);
    uint32_t offsize = 320*172*2 * curr_img_index;
    uint8_t start_y = 0;
    for(j=0;j<2;j++){
        _font->getimgData(offsize,color,320*160);
        offsize += 320*160;
        _lcd->draw_rectangle(0,start_y,320,start_y + 80,(uint16_t *)color);
        start_y += 80;
    }
    _font->getimgData(offsize,color,320*24);
    offsize += 320*24;
    _lcd->draw_rectangle(0,start_y,320,start_y + 12,(uint16_t *)color);
    start_y = 0;
    free(color);
}
void Aurora_Img::show_prev_img(){
    curr_img_index = ( curr_img_index == 0) ? curr_img_index : ( curr_img_index -1);
    uint16_t j;
    uint8_t *color = (uint8_t *)malloc(sizeof (uint8_t)*320*164);
    uint32_t offsize = 320*172*2 * curr_img_index;
    uint8_t start_y = 0;
    for(j=0;j<2;j++){
        _font->getimgData(offsize,color,320*160);
        offsize += 320*160;
        _lcd->draw_rectangle(0,start_y,320,start_y + 80,(uint16_t *)color);
        start_y += 80;
    }
    _font->getimgData(offsize,color,320*24);
    offsize += 320*24;
    _lcd->draw_rectangle(0,start_y,320,start_y + 12,(uint16_t *)color);
    start_y = 0;
    free(color);
}